/******************************************************************
 *
 *    tenant, Powered By uyun.cn.
 *
 *    Copyright (c) 2001-2020
 *    https://uyun.cn
 *
 *    Package:     wzg.com
 *
 *    Filename:    DealThread
 *
 *    Description: (用一句话描述该文件做什么)
 *
 *    Copyright:   Copyright (c) 2001-2020
 *
 *    Company:     uyun.cn
 *
 *    @author: 王志刚
 *
 *    @version: 1.0.0
 *
 *    Create at:   2018-01-02 下午4:44
 *
 *    Revision:
 *
 *    2018-01-02 下午4:44
 *        - first revision
 *
 *****************************************************************/
package wzg.com.deadthread;

/**
 * DealThread(这里用一句话描述这个类的作用)
 *
 * @author wangzg
 * @version 1.0.0
 * @create 2018-01-02 下午4:44
 */
public class DealThread implements Runnable {
    public  String username;
    public Object lock1 = new Object();
    public Object lock2 = new Object();

    public void setFlag(String username){
        this.username = username;
    }

    public void run(){
        if (username.equals("a")) {
            synchronized (lock1){
                try {
                    System.out.println("username="+username);
                    Thread.sleep(1000);
                }catch (Exception e){
                    e.printStackTrace();
                }
                synchronized (lock2){
                    System.out.println("a");
                }
            }
        }
        if (username.equals("b")) {
            synchronized (lock2){
                try {
                    System.out.println("username="+username);
                    Thread.sleep(1000);
                }catch (Exception e){
                    e.printStackTrace();
                }
                synchronized (lock1){
                    System.out.println("b");
                }
            }
        }
    }



}
